// ImageProcessor.h
#ifndef IMAGEPROCESSOR_H
#define IMAGEPROCESSOR_H

#include <opencv2/opencv.hpp>
#include <vector>

class ImageProcessor {
public:
    explicit ImageProcessor(const std::string& imagePath);
    ~ImageProcessor();

    bool processImage();
    cv::Mat getResultImage() const;
    cv::Mat getCroppedImage() const;

private:
    void convertToHSV();
    void defineColorRanges();
    void performColorSegmentation();
    void performMorphologicalOperations();
    void findAndFilterContours();
    void drawDetectionResults();
    void createCropMask();

    cv::Mat originalImage;
    cv::Mat hsvImage;
    cv::Mat combinedMask;
    cv::Mat resultImage;
    cv::Mat croppedImage;

    // 颜色范围定义
    struct ColorRange {
        cv::Scalar lower;
        cv::Scalar upper;
    };
    std::vector<ColorRange> blackRanges;
    std::vector<ColorRange> redRanges;
	std::vector<std::vector<cv::Point>> validContours;



    // 形态学操作参数
    cv::Mat kernel;
    int morphSize = 5;
};

#endif // IMAGEPROCESSOR_H